home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch17 / Arctan.bas < prev    next >
BASIC Source File  |  1999-06-06  |  470b  |  23 lines

  1. Attribute VB_Name = "Arctan"
  2. Option Explicit
  3.  
  4. ' Return the arctan of dy/dx.
  5. Public Function ATan2(ByVal dy As Single, ByVal dx As Single) As Single
  6. Const PI = 3.14159265
  7.  
  8. Dim theta As Single
  9.  
  10.     If Abs(dx) < 0.01 Then
  11.         If dy < 0 Then
  12.             theta = -PI / 2
  13.         Else
  14.             theta = PI / 2
  15.         End If
  16.     Else
  17.         theta = Atn(dy / dx)
  18.         If dx < 0 Then theta = PI + theta
  19.     End If
  20.  
  21.     ATan2 = theta
  22. End Function
  23.